package com.tarena.charging.order.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.charging.order.mapper.BillFailMapper;
import com.tarena.charging.order.mapper.BillSuccessMapper;
import com.tarena.charging.order.pojo.po.BillFailPO;
import com.tarena.charging.order.pojo.po.BillSuccessPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

//数据层开发的习惯 有一张需要操作的表格,就有一个数据层 repository+mapper
//BillSuccessMapper
//BillFailMapper
@Repository
public class BillRepository {
    @Autowired
    private BillSuccessMapper billSuccessMapper;
    @Autowired
    private BillFailMapper billFailMapper;

    public BillSuccessPO getSuccessBill(String billId) {
        //select * from charging_bill_success where bill_id=#{billId};
        QueryWrapper<BillSuccessPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("bill_id",billId);
        return billSuccessMapper.selectOne(queryWrapper);
    }

    public BillFailPO getFailBill(String billId) {
        QueryWrapper<BillFailPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("bill_id",billId);
        return billFailMapper.selectOne(queryWrapper);
    }

    public void saveFail(BillFailPO po) {
        billFailMapper.insert(po);
    }
}
